package homework;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @classname:demo08
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/16 19:58
 * @version: 0.1
 * @since:1.8
 */
public class demo08 {
    public static void main(String[] args) {
        ThreadLocalRandom localRandom = ThreadLocalRandom.current();
        List<Integer> list = new ArrayList<>(10);
        for (int i = 0; list.size() < 10; i++) {
            int i1 = localRandom.nextInt(1, 51);
            if (i1 % 2 == 0 && !(list.contains(i1))) {
                list.add(i1);
            }
        }
        Collections.sort(list, (o1, o2) -> o1.compareTo(o2));

        try (
                BufferedWriter writer = new BufferedWriter(new FileWriter("day16\\src\\c.txt"));
        ) {

            Iterator<Integer> iterator = list.iterator();
            int count = 0;
            int size = list.size();

            while (iterator.hasNext()) {
                Integer next = iterator.next();
                count++;
                if (count < size) {
                    //写入变成字符不是数字
                    writer.write(next.toString());
                    writer.write(",");
                } else {
                    writer.write(next.toString());
                }


            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
